package mylibrary.jndi;

import java.rmi.registry.LocateRegistry;
import java.util.Date;

import javax.naming.Context;
import javax.naming.InitialContext;

public class LocalJNDI {

	public static void main(String[] args) throws Exception {
		
		LocateRegistry.createRegistry(1099);
		
		System.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory");
		System.setProperty(Context.PROVIDER_URL, "rmi://localhost:1099");
		
		Context ctx = new InitialContext();
		
		Date dt = new RemoteDate();
		System.out.println(dt);
		
		ctx.bind("java:comp/env/systemStartTime", new RemoteDate());
		ctx.close();
		
		
		
		Context ctx1 = new InitialContext();
		Date d = (Date) ctx1.lookup("java:comp/env/systemStartTime");
		System.out.println(d);
	}
}
